package xiaochangsama.ancientkungfugeneration.procedures;

import xiaochangsama.ancientkungfugeneration.network.AncientKungfuGenerationModVariables;

import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.Entity;
import net.minecraft.network.chat.TextComponent;

public class JiangHuQiangGongBookLearnProcedure {
	public static void execute(Entity entity) {
		if (entity == null)
			return;
		if ((entity.getCapability(AncientKungfuGenerationModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new AncientKungfuGenerationModVariables.PlayerVariables())).JiangHuQingGong) {
			if (entity instanceof Player _player)
				_player.closeContainer();
			if (entity instanceof Player _player && !_player.level.isClientSide())
				_player.displayClientMessage(new TextComponent("\u00A7l\u4F60\u5DF2\u7ECF\u5B66\u4E60\u8FC7\u6C5F\u6E56\u8F7B\u529F\u4E86"), (true));
		} else {
			if (entity instanceof Player _player)
				_player.closeContainer();
			{
				boolean _setval = true;
				entity.getCapability(AncientKungfuGenerationModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
					capability.JiangHuQingGong = _setval;
					capability.syncPlayerVariables(entity);
				});
			}
			if (entity instanceof Player _player && !_player.level.isClientSide())
				_player.displayClientMessage(new TextComponent("\u00A7l\u4F60\u5B66\u4F1A\u4E86\u6C5F\u6E56\u8F7B\u529F\uFF01\uFF01\uFF01"), (true));
		}
	}
}
